<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'sys-member-form',
    'enableAjaxValidation' => false,
        ));


?>
<script language="javascript">
    var optionParentState = new Array();
    var valueParentState = new Array();
    var optionChildState = new Array();
    var valueChildState = new Array();
    var defaultChildIdState = '0';
    var defaultParentIdState = '0';
<?php
$q_parent = "SELECT area_id, area_name FROM ref_area WHERE area_par_id = '0'";
$r_parent = Yii::app()->db->createCommand($q_parent)->queryAll();
$i = 0;

foreach ($r_parent as $parent) {
    extract($parent);
    $q_child = "SELECT area_id AS id_child, area_name AS wil_child FROM ref_area WHERE area_par_id = '$area_id' ORDER BY area_name";
    $r_child = Yii::app()->db->createCommand($q_child)->queryAll();
    $arroptionChildState = "";
    $arrvalueChildState = "";

    foreach ($r_child as $child) {
        @extract($child);

        if ($id_child == $model->member_city_id) {
            $arroptionChildState .= "'===== $wil_child =====',";
        } else {
            $arroptionChildState .= "'$wil_child',";
        }

        $arrvalueChildState .= "'$id_child',";
        //$arrvalueChildState .= "'$wil_child',";
    }

    $arroptionChildState = substr($arroptionChildState, 0, -1);
    $arrvalueChildState = substr($arrvalueChildState, 0, -1);

    if ($area_id == $model->member_state_id) {
        ?>
                    optionParentState[<?= $i ?>] = '===== <?= $area_name ?> =====';
                    valueParentState[<?= $i ?>] = '<?= $area_id ?>';
        <?php
    } else {
        ?>
                    optionParentState[<?= $i ?>] = '<?= $area_name ?>';
                    valueParentState[<?= $i ?>] = '<?= $area_id ?>';
        <?php
    }
    ?>

            optionChildState[<?= $i ?>] = Array(<?= $arroptionChildState; ?>);
            valueChildState[<?= $i ?>] = Array(<?= $arrvalueChildState; ?>);
    <?php
    $i++;
}
?>

    function loadParent(parent, child)
    {
        if(parent.length <= 1)
        {
            parent.length = 0;
            for(var i = 0; i < optionParentState.length; i++)
            {
                parent.options[i] = new Option(optionParentState[i], valueParentState[i]);
                if(valueParentState[i] == '<?php echo function_lib::get_area_name($model->member_state_id); ?>') parent.options[i].selected = true;
            }

            //parent.options[defaultParentIdState].selected = true;
            loadChild(parent, child);
            //child.options[defaultChildIdState].selected = true;
        }
    }

    function loadChild(parent, child)
    {
        var currParent = parent.selectedIndex;

        child.length = 0;

        //if (currParent > 0)
        //{
        var curroptionChildState = optionChildState[currParent]; //.split(',');
        var currvalueChildState = valueChildState[currParent]; //.split(',');

        for(var i = 0; i < curroptionChildState.length; i++)
        {
            child.options[i] = new Option(curroptionChildState[i], currvalueChildState[i]);


            //child.options[0].selected = true;
            if(currvalueChildState[i] == '<?php echo function_lib::get_area_name($model->member_city_id); ?>') child.options[i].selected = true;
        }
        //}
    }

    var sval = '';
</script>
<div class="block">
    <div class="alert alert_grey">
        <img height="24" width="24" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/grey/alert_2.png">
        Fields with <span class="required"><strong>*</strong></span> are required.
    </div>

    <?php echo $form->errorSummary($model); ?>

    <?php echo $form->labelEx($model, 'member_name'); ?>
    <?php echo $form->textField($model, 'member_name', array('size' => 60, 'maxlength' => 100)); ?>
    <?php //echo $form->error($model,'member_name'); ?>

    <?php echo $form->labelEx($model, 'member_nickname'); ?>
    <?php echo $form->textField($model, 'member_nickname', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_nickname'); ?>

    <?php echo $form->labelEx($model, 'member_email'); ?>
    <?php echo $form->textField($model, 'member_email', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_email');  ?>

    <div class="input_group">
        <label for="sys_member_member_bank_id">Jenis Kelamin </label>
        <?php
                    $member_sex_option = array('male' => 'Laki-laki', 'female' => 'Perempuan');
                    echo CHtml::radioButtonList('sys_member[member_sex]', $model->member_sex, $member_sex_option, array('size' => 1, 'maxlength' => 1, 'labelOptions' => array('style' => 'display:inline; font-weight:normal;')));
                    ?>
    </div>

    <div class="input_group">
        <?php echo $form->labelEx($model, 'member_address'); ?>
        <?php echo $form->textField($model, 'member_address', array('size' => 50, 'maxlength' => 50)); ?>
        <?php //echo $form->error($model,'member_address');  ?>
    </div>
<div class="input_group">
    <label for="sys_member_member_bank_id">State </label>
        <select name="sys_member[member_state_id]" id="inputParent" onchange="loadChild(this, document.sys_member.inputChild);" onFocus="loadParent(this, document.sys_member.inputChild)">
                        <option value="<?php echo $model->member_state_id; ?>">===== <?php echo function_lib::get_area_name($model->member_state_id); ?> =====</option>
                    </select>
    </div>
    <div class="input_group">
        <label for="sys_member_member_bank_id">Province </label>
        <select name="sys_member[member_city_id]" id="inputChild">
                        <option value="<?php echo $model->member_city_id; ?>">===== <?php echo function_lib::get_area_name($model->member_city_id); ?> =====</option>
                    </select>
    </div>

    

   

    <?php echo $form->labelEx($model, 'member_zipcode'); ?>
    <?php echo $form->textField($model, 'member_zipcode', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_zipcode');  ?>

    <?php echo $form->labelEx($model, 'member_birth_place'); ?>
    <?php echo $form->textField($model, 'member_birth_place', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_birth_place');  ?>

    <div class="input_group">
        <?php echo $form->labelEx($model, 'member_birth_date'); ?>
        <?php
                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                        'model' => $model,
                        'attribute' => 'member_birth_date',
                        'options' => array(
                            'yearRange'=>'-80:+0',
                            'showAnim' => 'fold',
                            'dateFormat' => 'yy-mm-dd', // save to db format
                            'altField' => '#self_pointing_id',
                            'altFormat' => 'yy-mm-dd', // show to user format
                            'changeYear' => true,
                        ),
                        'htmlOptions' => array(
                            'style' => 'padding:3px 4px;',
                            'size' => 10,
                        ),
                    ));
                    ?>
    </div>

    <div class="input_group">
        <label for="sys_member_member_bank_id">No. Identitas </label>
        <?php
                    $member_identity_type_option = array('ktp' => 'KTP', 'sim' => 'SIM', 'passport' => 'Passport');
                    echo CHtml::radioButtonList('sys_member[member_identity_type]', $model->member_identity_type, $member_identity_type_option, array('size' => 1, 'maxlength' => 1, 'labelOptions' => array('style' => 'display:inline; font-weight:normal;')));
                    ?>
                    
    </div>

    <?php echo $form->labelEx($model, 'member_identity_no'); ?>
    <?php echo $form->textField($model, 'member_identity_no', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_identity_no');  ?>

    <?php echo $form->labelEx($model, 'member_phone'); ?>
    <?php echo $form->textField($model, 'member_phone', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_phone');  ?>

    <?php echo $form->labelEx($model, 'member_mobilephone'); ?>
    <?php echo $form->textField($model, 'member_mobilephone', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_mobilephone');  ?>

    <?php echo $form->labelEx($model, 'member_devisor_name'); ?>
    <?php echo $form->textField($model, 'member_devisor_name', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_devisor_name');  ?>

    <?php echo $form->labelEx($model, 'member_devisor_relationship'); ?>
    <?php echo $form->textField($model, 'member_devisor_relationship', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_devisor_relationship');  ?>

    <?php echo $form->labelEx($model, 'member_devisor_phone'); ?>
    <?php echo $form->textField($model, 'member_devisor_phone', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_devisor_phone');  ?>

    <div class="input_group">
        <label for="sys_member_member_bank_id">Bank </label>
        <?php
                    echo CHtml::activeDropDownList($model, 'member_bank_id', CHtml::listData(ref_bank::model()->findAll("bank_is_active = '1'"), 'bank_id', 'bank_name'));
                    ?>
    </div>

    <?php echo $form->labelEx($model, 'member_bank_city'); ?>
    <?php echo $form->textField($model, 'member_bank_city', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_bank_city');  ?>

    <?php echo $form->labelEx($model, 'member_bank_branch'); ?>
    <?php echo $form->textField($model, 'member_bank_branch', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_bank_branch');  ?>

    <?php echo $form->labelEx($model, 'member_bank_account_name'); ?>
    <?php echo $form->textField($model, 'member_bank_account_name', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_bank_account_name');  ?>

    <?php echo $form->labelEx($model, 'member_bank_account_no'); ?>
    <?php echo $form->textField($model, 'member_bank_account_no', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_bank_account_no');  ?>

    <?php echo $form->labelEx($model, 'member_tax_account_no'); ?>
    <?php echo $form->textField($model, 'member_tax_account_no', array('size' => 50, 'maxlength' => 50)); ?>
    <?php //echo $form->error($model,'member_tax_account_no');  ?>

    <button class="button_colour round_all"><img height="24" width="24" alt="Bended Arrow Right" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/white/bended_arrow_right.png"><span><?php echo ($model->isNewRecord) ? 'Create' : 'Save'; ?></span></button>

    <?php $this->endWidget(); ?>

</div>
<!-- form -->